<?php
class Navigation_m extends MY_Model{
	
	private $_table_lang = 'page_article_lang';
	private $select = 'p.id, p.created, p.create_by, p.parent_id, p._class, p.ordering, l.title, l.slug, l.keywords, l.description, l.uri';

	
	public function __construct(){
		parent::__construct();
		$this->_table = 'page_article';
	}
		
	//list de quy
	public function get_all($parent_id = 0, $level = 0,$start = 0, $end = 0){
		$this->_table = 'page_article p';
		$this->_table_lang = 'page_article_lang l';
		$this->db->select($this->select);
		$this->db->join($this->_table_lang,'p.id = l.id');
		$this->db->where('p.parent_id',$parent_id);
		$this->db->where('p.status',1);
		$this->db->where('l.lang',$this->_lang);
		$this->db->order_by('ordering');
		
		if($end){
			$this->db->limit($end,$start);
		}
		
		
		$result = $this->db->get($this->_table)->result();
		
		foreach($result as $item){
			$level++;
			$item->frefix = 'level'.$level;
			$item->class = 'hasChild';
			$item->child = $this->get_all($item->id,$level,100);
		}
		//print_r($result);
		return $result;
	}
}